var reply_pid = -1;

function show_reply(pid){
	$("#reply-feed-"+pid).html($('#reply-template').html());
	$("#modal-reply").modal({
	    backdrop:true,
	    show:true
	});
	$.get('/MyMicroBlog/index.php/reply/relpy_list?pid='+pid,function(result){
		$("#reply-feed-"+pid+' div.reply-list-container').html(result);
	});
}

function toggle_reply(pid){
	if(!$("#reply-feed-"+pid).children().size()){
		show_reply(pid);
	} else {
		$("#reply-feed-"+pid).children().remove();
	}
}

function remove_reply(pid){
	
}

function send_reply(anchor){
	var content = $(anchor).parents('div.relpy-body').find('textarea.reply-text').val();
	var reply_pid = $(anchor).parents('div.reply-ctn').attr('id').split('-')[2];
	if(!content){
		return;
	}
	console.log(content+' '+reply_pid);
	$.post('/MyMicroBlog/index.php/reply/add',{
			pid:reply_pid,
			content:content,
		},function(data,state,rqst){
			show_reply(reply_pid);
			numr = $("#btn-reply-"+reply_pid+' span');
			numr.html((numr.html()-0)+1);
			toastr.info('回复成功!');
		});
}